#include "StdAfx.h"
#include "pickearth.h"
#include <osgViewer/View>
#include <osgEarth/StringUtils>
#include <iostream>
#include <glibmm.h>
using namespace osg;
using namespace Glib;
pickearth::pickearth( osgEarth::TerrainEngineNode* terrainnode,osgEarth::Map *map,BJ::mainView  *mainview):_query(map)
{
   this->mainview  = mainview;
	this->map = map;
	_query.setMaxTilesToCache(10);
	_path.push_back(terrainnode);
}
bool pickearth::handle(const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter &us)
{

	bool  handleb  =osgEarth::Util::EarthManipulator::handle(ea,us);


	//if ( ea.getEventType() == osgGA::GUIEventAdapter::MOVE )
	if (ea.getEventType() == osgGA::GUIEventAdapter::DOUBLECLICK)
	{

	}
	if (0)
	{
		osgViewer::View* view = static_cast<osgViewer::View*>(us.asView());

		osgUtil::LineSegmentIntersector::Intersections results;

		if ( view->computeIntersections( ea.getX(), ea.getY(), _path, results ) )
		{

			osgUtil::LineSegmentIntersector::Intersection first = *(results.begin());
			osg::Vec3d point = first.getWorldIntersectPoint();
			osg::Vec3d lla;

			map.get()->worldPointToMapPoint(point, lla);

		}
	}


	return  handleb;
}

pickearth::~pickearth(void)
{
}
